<?php
/**
 * @version : 1.0
 * @since June-2008
 * @package : lib
 * @subpackage struct
 * @name :  CImage
 * @todo:  Lớp  cơ sở CMail. Gửi mail bằng SMTP của Gmail
 * 
*/
require '3rdparty/phpgmailer/class.phpgmailer.php';
class CMail
{
	/**
	 *  @example : 
	 * 	CMail(array(),'subject','body','vinhcv@yahoo.com')->send();
	 * 
		$subject = 'test';
		$body =  'body test';
		$recipient = 'khuyen_cntt@yahoo.com';
		CMail(array(),$subject,$body,$recipient)->send();
	 *
	 */
	public $options;
	public $subject;
	public $body;
	public $recipient;
	function __construct($options, $subject, $body, $recipient)
	{
		$this->options = array_merge(array(
			'from'=>'admin@tob365.com',
			'from_name' => 'Admin tob365',
			'username' => 'admin@tob365.com',
			'password' => 'abc123',
			'charset' => 'utf-8',
			'content_type' => 'text/html',
			'mailer' => 'smtp',
			'host' => '174.121.248.21',
			'smtp_auth' => true,
			'port' => 25
		), portal()->setting('mail'),$options);
		$this->subject = $subject;
		$this->body = $body;
		$this->recipient = $recipient;
	}
	
	function changeGmail($options){
		$this->options = array_merge($this->options, $options);
		return $this;
	}
	
	function send()
	{
		$email=new PHPGMailer();
		$email->From =$this->options['from'];
		$email->Mailer = $this->options['mailer'];
		$email->Host = $this->options['host'];
		$email->Port = $this->options['port'];
		$email->SMTPAuth = $this->options['smtp_auth'];
		$email->Username = $this->options['username'];
		$email->Password = $this->options['password'];
		$email->FromName = $this->options['from_name'];
		$email->CharSet= $this->options['charset'];
		$email->ContentType        = $this->options['content_type'];
		$email->Subject = $this->subject;
		$email->AddAddress($this->recipient);
		$email->Body = $this->body;
		return $email->Send();
	}
}
function CMail($options, $subject, $body, $recipient)
{
	return new CMail($options, $subject, $body, $recipient);
}
?>